mathod A (RC2rot): RC -> (trim) -> rotation
phi = 0, 120, -12 or 0, 90, -90
(1) Check the angle file
(2) Rocking curve (RC)
HW fitting angle = 0, 120(p120), -120(m120)
gauss fitting angle = 0, 120(p120), -120(m120)
Note: The fitting time depends on the capability of your PC.
(3) Image trimming
(4) Prepare the rotating data using image_editor
(5) Calculate q
(6) re-plot and re-analysis
# from pathlib import Path
# import matplotlib.pyplot as plt
# import mpl_toolkits.axes_grid1
# from mpl_toolkits.mplot3d import Axes3D
# import numpy as np
# import pandas as pd
# from PIL import Image
from qfit import make_angle_file as maf
from qfit import fit_q
from qfit import re_analysis as rean
from qfit import re_plot as replt
from qfit import multiplot as mlplt
from qfit import image_treat as imt
from qfit import file_folder_trans as fft
# import warnings
# warnings.simplefilter('ignore')
# # warnings.resetwarnings()
# # warnings.simplefilter('ignore', FutureWarning)
# %load_ext autoreload
# %autoreload 2
# Set target holder path
g_0 = r"D:\XrayDataset_for_paper\GaN_n1_4_0"
g_p120 = r"D:\XrayDataset_for_paper\GaN_n1_4_120"
g_m120 = r"D:\XrayDataset_for_paper\GaN_n1_4_m120"
# g_0 =r''
# g_p120 = r''
# g_m120 = r''
# Check if it contains tif data, angle.text, and dark tif data.
# phi=0
_ = maf.check_holder(data_path=g_0)
# phi=p120
_ = maf.check_holder(data_path=g_p120)
# phi=m120
_ = maf.check_holder(data_path=g_m120)
# If the angle file does not exist, go back to creating the angle file. -> temp_anglefile.ipynb
Data path:D:\XrayDataset_for_paper\GaN_n1_4_0 Dark file exist T/F: True Number of all tif files : 182 Number of tif data files without dark file: 181 tif data name: ['-165000.tif', '-166000.tif', '-167000.tif', '-168000.tif', '-169000.tif']...['-342000.tif', '-343000.tif', '-344000.tif', '-345000.tif', '-346000.tif'] angle file exist T/F: True ----- Data path:D:\XrayDataset_for_paper\GaN_n1_4_120 Dark file exist T/F: True Number of all tif files : 191 Number of tif data files without dark file: 190 tif data name: ['-340000.tif', '-341000.tif', '-342000.tif', '-343000.tif', '-344000.tif']...['-525000.tif', '-526000.tif', '-527000.tif', '-528000.tif', '-529000.tif'] angle file exist T/F: True ----- Data path:D:\XrayDataset_for_paper\GaN_n1_4_m120 Dark file exist T/F: True Number of all tif files : 158 Number of tif data files without dark file: 157 tif data name: ['165000.tif', '166000.tif', '167000.tif', '168000.tif', '169000.tif']...['317000.tif', '318000.tif', '319000.tif', '320000.tif', '321000.tif'] angle file exist T/F: True -----
# If the angle file exists, check the contents of the angle file
maf.anglefile_info(data_path=g_0)
print('-'*5)
maf.anglefile_info(data_path=g_p120)
print('-'*5)
maf.anglefile_info(data_path=g_m120)
Check angle file exist T/F: True Read angle file: angle filename 0 1650 -165000.tif 1 1660 -166000.tif 2 1670 -167000.tif 3 1680 -168000.tif 4 1690 -169000.tif Read angle file: angle filename 176 3420 -342000.tif 177 3430 -343000.tif 178 3440 -344000.tif 179 3450 -345000.tif 180 3460 -346000.tif ---------- ----- Check angle file exist T/F: True Read angle file: angle filename 0 3400 -340000.tif 1 3410 -341000.tif 2 3420 -342000.tif 3 3430 -343000.tif 4 3440 -344000.tif Read angle file: angle filename 185 5250 -525000.tif 186 5260 -526000.tif 187 5270 -527000.tif 188 5280 -528000.tif 189 5290 -529000.tif ---------- ----- Check angle file exist T/F: True Read angle file: angle filename 0 1650 165000.tif 1 1660 166000.tif 2 1670 167000.tif 3 1680 168000.tif 4 1690 169000.tif Read angle file: angle filename 152 3170 317000.tif 153 3180 318000.tif 154 3190 319000.tif 155 3200 320000.tif 156 3210 321000.tif ----------
# RC hw fitting
# core: Use multi-process PC cores.
# filter: Difference between median intensity and background. Nan value if below the filter.
# method: hw full width half maxima
cores = 6
t_file = g_0
t_folder,_ = fit_q.fit_analysis(target_file=t_file, filter=30, method='hw', comment='0data', core=cores)
print('')
c_file = g_p120
c_folder,_ = fit_q.fit_analysis(target_file=c_file, filter=30, method='hw', comment='p120data', core=cores)
print('')
a_file = g_m120
a_folder,_ = fit_q.fit_analysis(target_file=a_file, filter=30, method='hw', comment='m120data', core=cores)
print('')
# RC gauss fitting
# t_file = g_0
# t_folder, _ = fit_q.fit_analysis(target_file=t_file, filter=30, pmax=30, method='gaussian', comment='0data', core=cores)
# print('')
# c_file = g_p120
# c_folder,_ = fit_q.fit_analysis(target_file=c_file, filter=30, pmax=30, method='gaussian', comment='p120data', core=cores)
# print('')
# a_file = g_m120
# a_folder,_ = fit_q.fit_analysis(target_file=a_file, filter=30, pmax=30, method='gaussian', comment='m120data', core=cores)
# print('')
0data target file:D:\XrayDataset_for_paper\GaN_n1_4_0 Elasped time: 233.9[s] @ 6 cores Comment: 0data Output file name: hw_220623_140604_c.npy Folder name: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\hw_220623_140604 ---------- p120data target file:D:\XrayDataset_for_paper\GaN_n1_4_120 Elasped time: 289.9[s] @ 6 cores Comment: p120data Output file name: hw_220623_140955_c.npy Folder name: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\hw_220623_140955 ---------- m120data target file:D:\XrayDataset_for_paper\GaN_n1_4_m120 Elasped time: 213.5[s] @ 6 cores Comment: m120data Output file name: hw_220623_141445_c.npy Folder name: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\hw_220623_141445 ----------
# Check results
rc0 = rean.load_rc_tif(t_folder)
mlplt.rc_12plots(rc0, title='$\phi$=0')
rcp120 = rean.load_rc_tif(c_folder)
mlplt.rc_12plots(rcp120, title='$\phi$=p120')
rcm120 = rean.load_rc_tif(a_folder)
mlplt.rc_12plots(rcm120, title='$\phi$=m120')
# psi=0
# 2 inch: wh=1100, 4 inch: wh=2100, M:wh=500
# Wait a few seconds and a new GUI window will appear.
wh4 = 2150
wh2 = 1100
whm = 500
wh_set = wh4
tr_t_folder = imt.gui2trim(t_folder, wh=wh_set, NX=2368, NY=2240, time_out=120)
(2368, 2240) Quit -> press "ESC" Key start x:56, y:72 --wh:2150-- end x:2206, y:2222 start x:35, y:81 --wh:2150-- end x:2185, y:2231 start x:53, y:72 --wh:2150-- end x:2203, y:2222 start x:50, y:61 --wh:2150-- end x:2200, y:2211 start x:40, y:61 --wh:2150-- end x:2190, y:2211 final x: 40, y: 61 Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150) Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150) Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150)
# psi=p120
tr_c_folder = imt.gui2trim(c_folder, wh=wh_set, NX=2368, NY=2240, time_out=120)
(2368, 2240) Quit -> press "ESC" Key start x:89, y:134 --wh:2150-- end x:2239, y:2284 start x:50, y:100 --wh:2150-- end x:2200, y:2250 start x:43, y:84 --wh:2150-- end x:2193, y:2234 start x:48, y:56 --wh:2150-- end x:2198, y:2206 start x:40, y:81 --wh:2150-- end x:2190, y:2231 start x:45, y:61 --wh:2150-- end x:2195, y:2211 final x: 45, y: 61 Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150) Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150) Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150)
# psi=m120
tr_a_folder = imt.gui2trim(a_folder, wh=wh_set, NX=2368, NY=2240, time_out=120)
(2368, 2240) Quit -> press "ESC" Key start x:127, y:148 --wh:2150-- end x:2277, y:2298 start x:89, y:78 --wh:2150-- end x:2239, y:2228 start x:66, y:86 --wh:2150-- end x:2216, y:2236 start x:53, y:86 --wh:2150-- end x:2203, y:2236 start x:10, y:81 --wh:2150-- end x:2160, y:2231 start x:17, y:114 --wh:2150-- end x:2167, y:2264 start x:17, y:81 --wh:2150-- end x:2167, y:2231 start x:20, y:89 --wh:2150-- end x:2170, y:2239 final x: 20, y: 89 Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150) Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150) Original h(Y), w(X) : (2368, 2240) Trimmed h(Y), w(X) : (2150, 2150)
# Check results
rc0 = rean.load_rc_tif(tr_t_folder)
mlplt.rc_12plots(rc0, title='$\phi$=0')
# mlplt.rc_3plots(rc0, title='$\phi$=0', save=False, dpi=1800)
rcp120 = rean.load_rc_tif(tr_c_folder)
mlplt.rc_12plots(rcp120, title='$\phi$=p120')
rcm120 = rean.load_rc_tif(tr_a_folder)
mlplt.rc_12plots(rcm120, title='$\phi$=m120')
(1) Upper left window: Select data folder (phi=0)
(2) Set the reading step (1: all files, default 16)
(3) Middle left window: Select data folder (e.g. phi=120)
(4) Set the reading step (1: All files, default 16)
(5) If you need to flip the x-direction, set the scale original x to -1.
(6) Change the x,y, rotation, and scale parameters.
(7) Export from the File menu.
(8) Quit from the File menu.
# Wait a few seconds (10s - 60s) and a new GUI window will appear.
outfolderlist,_ = imt.img_editor_process()
print(outfolderlist)
[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445')]
# Check results
rc0 = rean.load_rc_tif(outfolderlist[0])
mlplt.rc_12plots(rc0, title='$\phi$=0')
rcp120 = rean.load_rc_tif(outfolderlist[1])
mlplt.rc_12plots(rcp120, title='$\phi$=p120')
rcm120 = rean.load_rc_tif(outfolderlist[2])
mlplt.rc_12plots(rcm120, title='$\phi$=m120')
# Set the data folder after rotation.
fr0 = outfolderlist[0]
frp120 = outfolderlist[1]
frm120 = outfolderlist[2]
print(fr0,frp120,frm120)
C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_140604 C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_140955 C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_141445
# convert tif to npy
r0 = fft.conv_tif2npy(file_dir=fr0)
rp120 = fft.conv_tif2npy(file_dir=frp120)
rm120 = fft.conv_tif2npy(file_dir=frm120)
# fft.fd_tif2fd_npy(file_dir=fr0)
# fft.fd_tif2fd_npy(file_dir=frp120)
# fft.fd_tif2fd_npy(file_dir=frm120)
# r0=fft.folder_file_list(fr0,look_for='npy')
# rp120=fft.folder_file_list(frp120,look_for='npy')
# rm120=fft.folder_file_list(frm120,look_for='npy')
print(f'phi=0')
print(r0)
print(f'phi=p120')
print(rp120)
print(f'phi=m120')
print(rm120)
npy list:[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604/rot_tr_hw_220623_140604_c.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604/rot_tr_hw_220623_140604_h.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604/rot_tr_hw_220623_140604_w.npy')]
npy list:[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955/rot_tr_hw_220623_140955_c.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955/rot_tr_hw_220623_140955_h.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955/rot_tr_hw_220623_140955_w.npy')]
npy list:[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445/rot_tr_hw_220623_141445_c.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445/rot_tr_hw_220623_141445_h.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445/rot_tr_hw_220623_141445_w.npy')]
phi=0
[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604/rot_tr_hw_220623_140604_c.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604/rot_tr_hw_220623_140604_h.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140604/rot_tr_hw_220623_140604_w.npy')]
phi=p120
[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955/rot_tr_hw_220623_140955_c.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955/rot_tr_hw_220623_140955_h.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_140955/rot_tr_hw_220623_140955_w.npy')]
phi=m120
[WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445/rot_tr_hw_220623_141445_c.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445/rot_tr_hw_220623_141445_h.npy'), WindowsPath('C:/Users/yagyu/Desktop/Xrdt_main/xrdt/rot_tr_hw_220623_141445/rot_tr_hw_220623_141445_w.npy')]
# The '_c.npy' file is used to calculate q.
target_t_ = r0[0]
target_c_ = rp120[0]
# set output folder name
out_file_ = '2R_0p120'
# phi=0
set_angle_t = 0
# phi=120
set_angle_c = 120
# If it is trimmed, change NX, NY.
# original NX=2368, NY=2240,
out_q_folder_0p = fit_q.q_analysis_2R(target_t=target_t_, target_c=target_c_, out_file=out_file_,
angle_t=set_angle_t, angle_c=set_angle_c,
q=6.258, NX=wh_set, NY=wh_set)
outfile name:2R_0p120 Image Size (h(NY),w(NX)):(2150, 2150) set Angle t: 0, c: 120 set target t: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_140604\rot_tr_hw_220623_140604_c.npy, c: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_140955\rot_tr_hw_220623_140955_c.npy ['NEW\r', 'set Angle t:0, c:120\r', '2R_0p120_f.png\r', 'Figure(640x480)\r', ''] ----------
target_t_ = r0[0]
target_c_ = rm120[0]
# set output folder name
out_file_ = '2R_0m120'
# phi=0
set_angle_t = 0
# phi=120
set_angle_c = -120
# If it is trimmed, change NX, NY.
out_q_folder_0m = fit_q.q_analysis_2R(target_t=target_t_, target_c=target_c_, out_file=out_file_,
angle_t=set_angle_t, angle_c=set_angle_c,
q=6.258, NX=wh_set, NY=wh_set)
outfile name:2R_0m120 Image Size (h(NY),w(NX)):(2150, 2150) set Angle t: 0, c: -120 set target t: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_140604\rot_tr_hw_220623_140604_c.npy, c: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_141445\rot_tr_hw_220623_141445_c.npy ['NEW\r', 'set Angle t:0, c:-120\r', '2R_0m120_f.png\r', 'Figure(640x480)\r', ''] ----------
target_t_ = rp120[0]
target_c_ = rm120[0]
# set output folder name
out_file_ = '2R_pm120'
# phi=0
set_angle_t = 120
# phi=120
set_angle_c = -120
# If it is trimmed, change NX, NY.
out_q_folder_pm = fit_q.q_analysis_2R(target_t=target_t_, target_c=target_c_, out_file=out_file_,
angle_t=set_angle_t, angle_c=set_angle_c,
q=6.258, NX=wh_set, NY=wh_set)
outfile name:2R_pm120 Image Size (h(NY),w(NX)):(2150, 2150) set Angle t: 120, c: -120 set target t: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_140955\rot_tr_hw_220623_140955_c.npy, c: C:\Users\yagyu\Desktop\Xrdt_main\xrdt\rot_tr_hw_220623_141445\rot_tr_hw_220623_141445_c.npy ['NEW\r', 'set Angle t:120, c:-120\r', '2R_pm120_f.png\r', 'Figure(640x480)\r', ''] ----------
# Check results
q_0p = rean.load_q_tif(out_q_folder_0p)
mlplt.qcp_12plots(q_0p, title='q (0,120)', step=100)
mlplt.qp_4plots(q_0p, title='q polar')
mlplt.qpa_3plots(q_0p, title='q polar analysis', step=150)
q_0m = rean.load_q_tif(out_q_folder_0m)
mlplt.qcp_12plots(q_0m, title='q (0,m120)', step=100)
q_pm = rean.load_q_tif(out_q_folder_pm)
mlplt.qcp_12plots(q_pm, title='q (p120,m120)', step=100)
# average q
ave_q= rean.average_3q(q_0p, q_0m, q_pm)
mlplt.qcp_12plots(ave_q, title='ave q', step=100)
mlplt.qp_4plots(ave_q, title='q polar')
mlplt.qpa_3plots(ave_q, title='q polar analysis', step=150)